package com.lzwork.gpt.utility.batchjob;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.lzwork.utility.collection.CollUtility;
import com.lzwork.utility.collection.MapReader;
import com.lzwork.utility.data.wrapper.BoolWrapper;
import com.lzwork.utility.data.wrapper.StringWrapper;
import com.lzwork.utility.pair.StringPair;
import com.lzwork.utility.str.StrUtility;
import com.lzwork.web.data.BoolResultInfo;
import com.lzwork.web.data.WebParamHolder;

/**
 * @author LiZheng
 * @date 2024年7月22日 14:32:48
 */

public class JobOption extends WebParamHolder
{
	protected String defIdKey()
	{
		return "";
	}

	protected String defContent()
	{
		return "";
	}

	protected StringWrapper idKey = new StringWrapper("idKey", defIdKey());
	protected StringWrapper contentKey = new StringWrapper("content", defContent());
	protected BoolWrapper useGbk = new BoolWrapper("useGbk", false);

	@Override
	protected void refreshParamInfo()
	{
		paramInfoMap.put(idKey.key(), new StringPair("ID字段名", "不能为空"));
		paramInfoMap.put(contentKey.key(), new StringPair("正文字段名", "不能为空"));
		paramInfoMap.put(useGbk.key(), new StringPair("是否使用GBK编码", "仅对Txt、CSV输入生效，默认UTF-8编码"));
	}

	public String getIdKey()
	{
		return idKey.value();
	}

	public String getContentKey()
	{
		return contentKey.value();
	}

	public boolean useGbk()
	{
		return useGbk.value();
	}

	public Charset charset()
	{
		return useGbk.value() ? Charset.forName("GBK") : StandardCharsets.UTF_8;
	}

	public List<String> requireFields()
	{
		return CollUtility.arrayToList(idKey.value(), contentKey.value());
	}

	public List<String> fieldFilter()
	{
		return new ArrayList<>();
	}

	@Override
	protected BoolResultInfo validateInput(Map<?, ?> map)
	{
		String idKey = MapReader.getMapStr(map, "idKey");
		if (!StrUtility.stringValid(idKey))
			return BoolResultInfo.makeFalse("工单ID字段名不可为空");

		String content = MapReader.getMapStr(map, "content");
		if (!StrUtility.stringValid(content))
			return BoolResultInfo.makeFalse("正文字段名不可为空");

		return BoolResultInfo.makeTrue("");
	}
}
